import Vue from "vue"

import axios from "./axios.js";
import store from "./store/index.js"
import router from "./router/index.js"

Vue.mixin({
	methods: {
		hasAuth(perm) {
			var authority = this.$store.state.menus.permList

			return authority.indexOf(perm) > -1
		},
		refreshMenu(){
			axios.get("/sys/menu/nav", { //进入菜单导航栏
				headers: {
					Authorization: localStorage.getItem("token")
				}
			}).then(res => {
				// console.log(res.data.data)
				// 拿到menuList
				store.commit("setMenuList", res.data.data.nav)
				// 拿到用户权限
				store.commit("setPermList", res.data.data.authoritys)
			
				// console.log(store.state.menus.menuList)
				// 动态绑定路由
				// let newRoutes = router.options.routes
				// let newRoutes = this.routes
				
				// let RoutesName = Array();
				// for(let key in newRoutes[0].children){
				// 	RoutesName.push(newRoutes[0].children[key]["name"]);
				// }
				
				// res.data.data.nav.forEach(menu => {
				// 	if (menu.children) {
				// 		menu.children.forEach(e => {
				// 			// 转成路由
				// 			let route = this.menuToRoute(e)
				// 			// 把路由添加到路由管理中
				// 			if (route) {
				// 				console.log(route["name"])
				// 				console.log(RoutesName.includes(route["name"]))
				// 				// console.log(newRoutes[0].children.includes(route))
				// 				if(!RoutesName.includes(route["name"])){
				// 					newRoutes[0].children.push(route)
				// 				}
				// 			}
				// 		})
				// 	}
				// })
							
				// console.log("newRoutes")
				// console.log(newRoutes)
				// //动态添加路由
				// test.resetRouter(this.routes) 
				// console.log(router)
			})
		},
	}
})